package com.atguigu.order.controller;

import com.atguigu.order.service.OrderService;
import com.atguigu.param.CartListParam;
import com.atguigu.param.OrderParam;
import com.atguigu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName:OrderController
 * Package:com.atguigu.order.controller
 * Description:
 *
 * @Author 应永豪
 * @Create 2024/4/22 21:57
 * @Version 1.0
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @PostMapping("save")
    public R save(@RequestBody OrderParam orderParam){
        return orderService.save(orderParam);

    }

    @PostMapping("list")
    public R list(@RequestBody @Validated CartListParam cartListParam, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return R.fail("参数异常,查询失败");
        }

        return orderService.list(cartListParam.getUserId());

    }
}
